package com.junmiao.A.execution;

import java.util.ArrayList;

import org.apache.http.nio.reactor.IOReactorException;

import com.junmiao.A.dataSource.DataSource;
import com.junmiao.A.dataSource.SinaGGTJDataSource;
import com.junmiao.A.dataSource.SinaJSDataSource;
import com.junmiao.A.dataSource.SinaStockDataSource;
import com.junmiao.A.dataSource.SohuStockDataSource;
import com.junmiao.A.stock.utils.ParseSinaData;
import com.junmiao.A.stock.utils.ParseSohuStock;
import com.junmiao.A.stockModel.SinaGGTJBean;
import com.junmiao.A.stockModel.SinaJSBean;
import com.junmiao.A.stockModel.SinaStockBean;
import com.junmiao.A.stockModel.SohuStockBean;

public class Execution {

	public static ArrayList<SinaStockBean> executeSinaStock()
	{
		 DataSource ds = new SinaStockDataSource();
		 return executeSinaStock(ds);
	}
	// SinaStock
	public static ArrayList<SinaStockBean> executeSinaStock(DataSource ds) {


		ArrayList<String> dataSource = ds.getDataSource();

		long start = System.currentTimeMillis();

		ArrayList<SinaStockBean> ssbResults = new ArrayList<SinaStockBean>();
		try {

			ParseSinaData.parseSinaStock(dataSource, ssbResults);

		} catch (IOReactorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
/*
		if (ssbResults != null && ssbResults.size() > 0) {
			for (SinaStockBean ssb : ssbResults) {

				if (ssb != null) {
					if(ssb.getShareHolders()!=null && ssb.getShareHolders().size()==10){
					System.out.println(ssb.getStockNo() + " : "
							+ ssb.getStockName() + " : no " + ssb.getShareHolders().size()
							+ " : name " + ssb.getShareHolders().get(3).getName());
					}else{
						System.out.println(ssb.getStockNo() + " : "
								+ ssb.getStockName() + " : Information  unknown " );
					}
				}

			}
		}
		*/
		long end = System.currentTimeMillis();
		long diff = end - start;
		System.out.println("Time cost " + diff + "ms");
		
		return ssbResults;
	}
	
	
	public static ArrayList<SinaJSBean> executeSinaJS() {
		
		DataSource ds = new SinaJSDataSource();
		return executeSinaJS(ds);
	}
	//SinaJS 
	public static ArrayList<SinaJSBean> executeSinaJS(DataSource ds) {

		//DataSource ds = new SinaJSDataSource();

		ArrayList<String> dataSource = ds.getDataSource();

		long start = System.currentTimeMillis();

		ArrayList<SinaJSBean> sjsResults = new ArrayList<SinaJSBean>();
		try {

			ParseSinaData.parseSinaJS(dataSource, sjsResults);

		} catch (IOReactorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
/*
		if (sjsResults != null && sjsResults.size() > 0) {
			for (SinaJSBean sjs : sjsResults) {

				if (sjs != null) {
					System.out.println(sjs.getStockNo() + " : "
							+ sjs.getStockName() + " : " + sjs.getToday_close()
							+ " : " + sjs.getToday_high() + " : "
							+ sjs.getToday_low() + " : " + sjs.getToday_open()
							+ " : " + sjs.getLastday_close() + " : "
							+ sjs.getDate());

				}

			}
		}
		*/
		long end = System.currentTimeMillis();
		long diff = end - start;
		System.out.println("Time cost " + diff + "ms");
		return sjsResults;
	}

	//Sina GGTJ
	public static ArrayList<SinaGGTJBean> executeSinaGGTJ() {
		DataSource ds = new SinaGGTJDataSource();
		return executeSinaGGTJ(ds);
	}
	//Sina GGTJ
	public static ArrayList<SinaGGTJBean> executeSinaGGTJ(DataSource ds) {

		//DataSource ds = new SinaGGTJDataSource();

		ArrayList<String> dataSource = ds.getDataSource();

		long start = System.currentTimeMillis();

		ArrayList<SinaGGTJBean> ggtjResults = new ArrayList<SinaGGTJBean>();
		try {

			ParseSinaData.parseSinaGGTJ(dataSource, ggtjResults);

		} catch (IOReactorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
/*
		if (ggtjResults != null && ggtjResults.size() > 0) {
			for (SinaGGTJBean ggtj : ggtjResults) {

				if (ggtj != null) {
					System.out.println(ggtj.getStockNo() + " : "
							+ ggtj.getStockName() + " : "
							+ ggtj.getOrg_hold_today() + " : "
							+ ggtj.getIndiv_hold_5() + " : "
							+ ggtj.getOrg_hold_today() + " : "
							+ ggtj.getIndiv_hold_5() + " : "
							+ ggtj.getStock_org_hold());

				}

			}
		}
		*/
		long end = System.currentTimeMillis();
		long diff = end - start;
		System.out.println("Time cost " + diff + "ms");
		return ggtjResults;
	}
	
	//Sohu
	public static ArrayList<SohuStockBean> executeSohuStock() {
		
		DataSource ds = new SohuStockDataSource();
		return executeSohuStock(ds);
	}

	//Sohu
	public static ArrayList<SohuStockBean> executeSohuStock(DataSource ds) {

		//DataSource ds = new SohuStockDataSource();

		ArrayList<String> dataSource = ds.getDataSource();

		long start = System.currentTimeMillis();

		ArrayList<SohuStockBean> shskResults = new ArrayList<SohuStockBean>();
		try {

			ParseSohuStock.parseSohuStock(dataSource, shskResults);

		} catch (IOReactorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
/*
		if (shskResults != null && shskResults.size() > 0) {
			for (SohuStockBean shsk : shskResults) {

				if (shsk != null) {
					System.out.println(shsk.getStockNo() + " : "
							+ shsk.getStockName() + " : 5_zf "
							+ shsk.getBiao_xian_5_day() + " : 10_zf "
							+ shsk.getBiao_xian_10_day() + " : 5_hs "
							+ shsk.getHuan_shou_5_day() + " : 10_hs "
							+ shsk.getHuan_shou_10_day() + " : jl_zzl "
							+ shsk.getJin_li_zen_zhang() + " : jzc_syl "
							+ shsk.getJin_zi_zhan_shou_yi_lv() + " : mg_jzc "
							+ shsk.getMei_gu_jin_zi_chan() + " : mg_syl " 
							+ shsk.getMei_gu_shou_yi() + " : mg_wfp "
							+ shsk.getMei_gu_wei_fen_pei() + " : mg_zb_gjj "
							+ shsk.getMei_gu_zi_ben_gong_ji_jin() + " : zy_zc" 
							+ shsk.getZhu_yin_zen_zhan_lv() + " : yearHigh "
							+ shsk.getYearHigh() + " : yearLow " 
							+ shsk.getYearLow() + " : zongguben " 
							+ shsk.getZong_gu_bin() + " : liutongbuben "
							+ shsk.getLiu_tong_gu_ben());

				}

			}
		}
		*/
		long end = System.currentTimeMillis();
		long diff = end - start;
		System.out.println("Time cost " + diff + "ms");
		
		return shskResults;
	}
}
